package com.leyou.search.web;

import com.leyou.search.dto.SearchParamDTO;
import com.leyou.search.entity.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

/**
 * @author mySun
 * @create 2021-07-21 17:08
 */
@RestController
@RequestMapping("/goods")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @RequestMapping("/suggestion")
    public Mono<List<String>> suggestion(@RequestParam("key")String key){
        return searchService.getSuggestion(key);
    }

    /**
     * 分页查询
     * @param searchParamDTO
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>> pageGoods(@RequestBody SearchParamDTO searchParamDTO){
        return searchService.pageGoods(searchParamDTO);
    }

    /**
     * 根据搜索条件返回过滤条件
     * @param searchParamDTO key为搜索条件
     * @return Map<String,List<?> key为过滤名，value为过滤名对应的所有值
     */
    @PostMapping("/filter")
    public Mono<Map<String,List<?>>> getFilterCondition(@RequestBody SearchParamDTO searchParamDTO){
        return searchService.getFilterCondition(searchParamDTO);
    }

}
